package com.example.service;

import com.example.dto.BaseReq;
import com.example.dto.BaseResp;
import io.seata.spring.annotation.GlobalTransactional;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

@Service
public class OrderService {
    @Autowired
    private JdbcTemplate jdbcTemplate;
    
    @Autowired
    private RestTemplate restTemplate;
    
    @GlobalTransactional(name = "for-create-order", rollbackFor = Exception.class)
    public void order() {
        jdbcTemplate.execute(" INSERT INTO `order` (goods_id, order_no, amount) VALUES ('1', '110', 123) ");
        BaseReq req = new BaseReq();
        restTemplate.postForObject("http://seata-account-service/account", req, BaseResp.class);
        restTemplate.postForObject("http://seata-storage-service/storage", req, BaseResp.class);
        int i = 1/0;
    }
    
}
